<!-- 取消订单 -->
<template>
  <el-dialog v-model="dialogVisible" title="变更所属基地" width="35%" top="30vh" class="base_dialog" @open="resetForm(formRef)">
    <el-form ref="formRef" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="基地名称" prop="base">
        <el-select v-model="form.base" placeholder="请选择基地" clearable>
          <el-option v-for="(item, index) in baseOptions" :key="index" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="submitForm(formRef)">保存</el-button>
        <el-button @click="dialogVisible = false">取消</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref, reactive, defineEmits, defineExpose } from "vue";
import api from "@api/config"

const emit = defineEmits(["changeShop"]);

const dialogVisible = ref(false);

function show() {
  dialogVisible.value = true;
}

defineExpose({ show });

const baseOptions = ref([]);

getConfig()

function getConfig() {
  api.base(val => {
    baseOptions.value = val
  })
}

const formRef = ref(null);

const form = reactive({
  base: null,
});

const rules = {
  base: [
    {
      required: true,
      message: "请选择基地",
      trigger: "change",
    },
  ],
};

const submitForm = (formEl) => {
  if (!formEl) return;
  formEl.validate((valid, fields) => {
    if (valid) {
      emit("changeShop", form);
      dialogVisible.value = false
    }
  });
}

const resetForm = (formEl) => {
  if (!formEl) return;
  formEl.resetFields();
}
</script>
